import {WebviewWindow} from "@tauri-apps/api/webviewWindow";
import {invoke} from "@tauri-apps/api/core";
import {storeToRefs} from "pinia";
import {useUserStore} from "../stores/user.ts";

export async function openMainWindow(user) {
    let {userInfo} = storeToRefs(useUserStore())
    // window successfully created
    let mainWebviewWindow = new WebviewWindow('mainWebviewWindow',{
        url:'/main',
        width: 830,
        height: 550,
        label: "main",
        title: "嘻哈聊天",
        resizable: false,
        fullscreen: false,
        visible: true
    });
    await mainWebviewWindow.once('tauri://created', function () {
        // webview successfully created
        userInfo.value = {
            account: user.account,
            nickname: user.account,
            token: user.token,
            login: true
        };
        invoke('connect', {}).then(async () => {
            //await WebviewWindow.getByLabel('login').close();
            console.log('connect success')
        });
    });
}